|
1
|
|
|
var chai = require('chai'); |
|
2
|
|
|
var path = require('path'); |
|
3
|
|
|
|
|
4
|
|
|
var config = require('../src/cli').config |
|
5
|
|
|
config.set({root: path.join(__dirname,'fixtures')}) |
|
6
|
|
|
|
|
7
|
|
|
var cmsOperations = require('../src/cli').cmsOperations |
|
8
|
|
|
var Manager = require('../src/cli').Manager; |
|
9
|
|
|
var fse = require('fs-extra'); |
|
10
|
|
|
|
|
11
|
|
|
describe('cmsOperations', function() { |
|
12
|
|
|
before( function(done) { |
|
13
|
|
|
Manager.instance.init() |
|
14
|
|
|
.then(function () { |
|
15
|
|
|
Manager.instance._whereKeys = ['title', 'priority', 'abe_meta', 'articles'] |
|
16
|
|
|
Manager.instance.updateList() |
|
17
|
|
|
|
|
18
|
|
|
this.fixture = { |
|
19
|
|
|
jsonArticle: fse.readJsonSync(path.join(__dirname, '/fixtures/files/article-2.json')), |
|
20
|
|
|
jsonHomepage: fse.readJsonSync(path.join(__dirname, '/fixtures/data/homepage-1.json')) |
|
21
|
|
|
} |
|
22
|
|
|
done() |
|
23
|
|
|
|
|
24
|
|
|
}.bind(this)) |
|
25
|
|
|
}); |
|
26
|
|
|
|
|
27
|
|
|
it('cmsOperations.create()', function(done) { |
|
28
|
|
|
cmsOperations.create('article', '', 'article-2.html', {query: ''}, JSON.parse(JSON.stringify(this.fixture.jsonArticle)), false) |
|
29
|
|
|
.then(function(resSave) { |
|
30
|
|
|
var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json')) |
|
31
|
|
|
var stat = fse.statSync(json) |
|
32
|
|
|
if (stat) { |
|
33
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
34
|
|
|
} |
|
35
|
|
|
fse.removeSync(json) |
|
36
|
|
|
done() |
|
37
|
|
|
}.bind(this)); |
|
|
|
|
|
|
38
|
|
|
}); |
|
39
|
|
|
|
|
40
|
|
|
/** |
|
41
|
|
|
* cmsOperations.post.publish |
|
42
|
|
|
* |
|
43
|
|
|
*/ |
|
44
|
|
|
it('cmsOperations.post.publish()', function(done) { |
|
45
|
|
|
cmsOperations.post.publish('article-2.html', JSON.parse(JSON.stringify(this.fixture.jsonArticle))) |
|
46
|
|
|
.then(function(resSave) { |
|
47
|
|
|
var json = path.join(config.root, config.data.url, resSave.json.abe_meta.latest.abeUrl.replace('.html', '.json')) |
|
48
|
|
|
var stat = fse.statSync(json) |
|
49
|
|
|
if (stat) { |
|
50
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
51
|
|
|
} |
|
52
|
|
|
fse.removeSync(json) |
|
53
|
|
|
|
|
54
|
|
|
var html = path.join(config.root, config.publish.url, resSave.json.abe_meta.link) |
|
55
|
|
|
var stat = fse.statSync(html) |
|
|
|
|
|
|
56
|
|
|
if (stat) { |
|
57
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
58
|
|
|
} |
|
59
|
|
|
fse.removeSync(html) |
|
60
|
|
|
done() |
|
61
|
|
|
}.bind(this)); |
|
|
|
|
|
|
62
|
|
|
}); |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* cmsOperations.post.unpublish |
|
66
|
|
|
* |
|
67
|
|
|
*/ |
|
68
|
|
|
it('cmsOperations.post.unpublish()', function(done) { |
|
69
|
|
|
cmsOperations.post.publish('article-2.html', JSON.parse(JSON.stringify(this.fixture.jsonArticle))) |
|
70
|
|
|
.then(function(resSave) { |
|
71
|
|
|
var json = path.join(config.root, config.data.url, resSave.json.abe_meta.latest.abeUrl.replace('.html', '.json')) |
|
72
|
|
|
var html = path.join(config.root, config.publish.url, resSave.json.abe_meta.link) |
|
73
|
|
|
cmsOperations.post.unpublish('article-2.html') |
|
74
|
|
|
.then(function(resSave2) { |
|
75
|
|
|
var stat |
|
76
|
|
|
try { |
|
77
|
|
|
var stat = fse.statSync(json) |
|
|
|
|
|
|
78
|
|
|
}catch(e) { |
|
79
|
|
|
chai.expect(stat).to.be.undefined; |
|
|
|
|
|
|
80
|
|
|
} |
|
81
|
|
|
try { |
|
82
|
|
|
var stat = fse.statSync(html) |
|
|
|
|
|
|
83
|
|
|
}catch(e) { |
|
84
|
|
|
chai.expect(stat).to.be.undefined; |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
json = path.join(config.root, config.data.url, resSave2.json.abe_meta.latest.abeUrl.replace('.html', '.json')) |
|
87
|
|
|
var stat = fse.statSync(json) |
|
|
|
|
|
|
88
|
|
|
if (stat) { |
|
89
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
fse.removeSync(json) |
|
92
|
|
|
done() |
|
93
|
|
|
}.bind(this)); |
|
|
|
|
|
|
94
|
|
|
}.bind(this)); |
|
95
|
|
|
}); |
|
96
|
|
|
|
|
97
|
|
|
/** |
|
98
|
|
|
* cmsOperations.post.draft |
|
99
|
|
|
* |
|
100
|
|
|
*/ |
|
101
|
|
|
it('cmsOperations.post.draft()', function(done) { |
|
102
|
|
|
cmsOperations.post.draft('article-2.html', JSON.parse(JSON.stringify(this.fixture.jsonArticle))) |
|
103
|
|
|
.then(function(resSave) { |
|
104
|
|
|
var json = path.join(config.root, config.data.url, resSave.json.abe_meta.latest.abeUrl.replace('.html', '.json')) |
|
105
|
|
|
var stat = fse.statSync(json) |
|
106
|
|
|
if (stat) { |
|
107
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
108
|
|
|
} |
|
109
|
|
|
fse.removeSync(json) |
|
110
|
|
|
done() |
|
111
|
|
|
}.bind(this)); |
|
|
|
|
|
|
112
|
|
|
}); |
|
113
|
|
|
|
|
114
|
|
|
/** |
|
115
|
|
|
* cmsOperations.post.reject |
|
116
|
|
|
* |
|
117
|
|
|
*/ |
|
118
|
|
|
it('cmsOperations.post.reject()', function(done) { |
|
119
|
|
|
cmsOperations.post.reject('article-2.html', JSON.parse(JSON.stringify(this.fixture.jsonArticle))) |
|
120
|
|
|
.then(function(resSave) { |
|
121
|
|
|
var json = path.join(config.root, config.data.url, resSave.json.abe_meta.latest.abeUrl.replace('.html', '.json')) |
|
122
|
|
|
var stat = fse.statSync(json) |
|
123
|
|
|
if (stat) { |
|
124
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
125
|
|
|
} |
|
126
|
|
|
fse.removeSync(json) |
|
127
|
|
|
done() |
|
128
|
|
|
}.bind(this)); |
|
|
|
|
|
|
129
|
|
|
}); |
|
130
|
|
|
|
|
131
|
|
|
it('cmsOperations.duplicate()', function(done) { |
|
132
|
|
|
cmsOperations.duplicate('article-1.html', 'article', '', 'article-2.html', {}, false) |
|
133
|
|
|
.then(function(resSave) { |
|
134
|
|
|
var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json')) |
|
135
|
|
|
var stat = fse.statSync(json) |
|
136
|
|
|
if (stat) { |
|
137
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
138
|
|
|
} |
|
139
|
|
|
fse.removeSync(json) |
|
140
|
|
|
done() |
|
141
|
|
|
}.bind(this)) |
|
|
|
|
|
|
142
|
|
|
}); |
|
143
|
|
|
|
|
144
|
|
|
it('cmsOperations.duplicate() update', function(done) { |
|
145
|
|
|
cmsOperations.duplicate('article-1.html', 'article', '', 'article-1.html', {}, true) |
|
146
|
|
|
.then(function(resSave) { |
|
147
|
|
|
var json = path.join(config.root, config.data.url, resSave.abe_meta.latest.abeUrl.replace('.html', '.json')) |
|
148
|
|
|
var stat = fse.statSync(json) |
|
149
|
|
|
if (stat) { |
|
150
|
|
|
chai.expect(stat).to.not.be.undefined; |
|
|
|
|
|
|
151
|
|
|
} |
|
152
|
|
|
fse.removeSync(json) |
|
153
|
|
|
done() |
|
154
|
|
|
}.bind(this)) |
|
|
|
|
|
|
155
|
|
|
}); |
|
156
|
|
|
}); |
|
157
|
|
|
|